﻿@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}
@model Beway.ValueAdded.Model.ReUser
@section HeadSection
{
    <script type="text/javascript">
         var role = "@Session["role"]";
        var url = "";
        $(function () {
            $('#ReUserList').datagrid({
                title: '充值项目管理',
                iconCls: 'icon-edit',
                url: '/ReUser/ReUserList',
                striped: true,
                idField: 'UserID',
                border: true,
                loadMsg: '数据加载中...',
                singleSelect: true,
                pagination: true,
                pageSize: 10,
                pageList: [10, 20],
                frozenColumns: [[{ field: 'ck', checkbox: true }]],
                columns: [[
                    { field: 'UserID', title: '项目ID', width: 50, align: 'center' },
                    { field: 'UserTitle', title: '项目名称', width: 200 },
                    { field: 'AdminTrueName', title: '项目经理', width: 80, align: 'center' },
                    { field: 'AdminMobile', title: '项目经理手机', width: 90, align: 'center' },
                         {
                             field: 'RechStatus', title: '账户状态', width: 120, align: 'center', formatter: function (val, rec) {
                                 if (val == 1) {
                                     return "<font style='color:green;'>启用</font>";
                                 }
                                 else {
                                     return "<font style='color:red;'>禁用</font>";
                                 }
                             }
                    },
                         {
                             field: 'BeginTime', title: '项目时间', width: 240, align: 'center', formatter: function (v, rec) {
                                 return JSONDateToJSDate(v) + ' - ' + JSONDateToJSDate(rec.EndTime);

                             }
                         },
                         {
                             field: 'RechAmount', title: '剩余额/总预算(元)', width: 110, align: 'center', formatter: function (val, rec) {
                                 return "<span style='color:green;'>" + rec.RechStock + "</span>/<span style='color:red'>" + val + "</span>";
                             }
                         },
                         {
                             field: 'RechAlarm', title: '剩余预警(元)', width: 80, align: 'center', formatter: function (val) {
                                 return "<span style='color:red'>" + val + "</span>";
                             }
                         },
                         {
                             field: 'RechDayTotal', title: '每天充值限额(元)', width: 180, align: 'center', formatter: function (val) {
                                 return "<span style='color:red'>" + val + "</span>";
                             }
                         },
                        {
                            field: 'AddTime', title: '添加时间', width: 120, align: 'center', formatter: function (val, rec) {
                                return JSONDateToJSDate(val);
                            }
                        },
                        {
                            field: 'tel', title: '报表', width: 250, align: 'center', formatter: function (val, rec) {
                                return '<a href="/Report/ReportDetail?rcType=' + "1" + "&userId=" + rec.UserID + '&userTitle=' + rec.UserTitle + '">话费</a>&nbsp;&nbsp;' +
                                    '<a href="/Report/ReportDetail?rcType=' + "2" + "&userId=" + rec.UserID + '&userTitle=' + rec.UserTitle + '">Q币</a>&nbsp;&nbsp;' +
                                        '<a href="/Report/ReportDetail?rcType=' + "3" + "&userId=" + rec.UserID + '&userTitle=' + rec.UserTitle + '">礼品卡</a>&nbsp;&nbsp;' +
                                     '<a href="/Report/ReportDetail?rcType=' + "4" + "&userId=" + rec.UserID + '&userTitle=' + rec.UserTitle + '">流量包</a>&nbsp;&nbsp;'+
                                    '<a href="/Report/ReportDetail?rcType=' + "5" + "&userId=" + rec.UserID + '&userTitle=' + rec.UserTitle + '">微信红包</a>';
                            }
                        }
                ]], toolbar: [{
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () {
                        newReUser();
                    }
                }, '-', {
                    text: '编辑',
                    iconCls: 'icon-edit',
                    handler: function () {
                        editReUser();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        delReUser();
                    }
                }, '-']
            });

            //尺寸
            $('#ReUserList').datagrid('resize');

            //加载搜索框//在这个样式下。加载搜索框的div
            $(".datagrid-toolbar").append($("#divsearch"));

            //绑定项目经理账号
            bindAdminCombogrid("AdminId");

            //生成key
            $("#btnGenKey").click(function () {
                $.post("/reuser/GenerateKey", { r: Math.random() }, function (d) {
                    $("#VerifyMac").val(d.key);
                })
            })
        });

        //搜索
        function doSearch() {
            $('#ReUserList').datagrid('load', { UserName: $("#UserName").val() });
        }

        //新增
        function newReUser() {
            if (role == 0) {
                $("#DivUserName").show();
                url = "/ReUser/AddReUser";
                $("#dlg").dialog('open').dialog('setTitle', '添加充值项目管理');
                $("#fm").form('clear');
            }
            else {
                alert("抱歉，项目经理不能新增充值项目。");
            }
        }
        //新增确定
        function ReUserSave() {
            $.messager.progress();
            $("#fm").form('submit', {
                url: url,
                onSubmit: function () {
                    if (!$(this).form('validate')) {
                        $.messager.progress('close');
                        return false;
                    }
                },
                success: function (result) {
                    $.messager.progress('close');
                    if (result > 0) {
                        $("#dlg").dialog('close');
                        $.messager.alert('提示', '信息保存成功');
                        $("#ReUserList").datagrid('reload');
                    } else if (result == -5) {
                        $.messager.show({
                            title: 'Error',
                            msg: "该用户名已经存在"
                        }
                        );
                    }
                    else {
                        $.messager.show({
                            title: 'Error',
                            msg: "保存信息失败"
                        }
                        );
                    }
                }
            });
        }
        //编辑
        function editReUser() {
            var row = $("#ReUserList").datagrid('getSelected');
            if (row) {
                $("#dlg").dialog('open').dialog('setTitle', '编辑充值项目');
                $('#BeginTime').datetimebox('setValue', JSONDateToJSDate(row.BeginTime));
                $('#EndTime').datetimebox('setValue', JSONDateToJSDate(row.EndTime));

                //$("#fm").form('load', row);

                url = "/ReUser/UpdateReUser";

                $("#UserTitle").val(row.UserTitle);
                $("#AdminId").combogrid('setValue', row.AdminId);
                $("#RechAlarm").numberbox('setValue', row.RechAlarm);
                $("#VerifyMac").val(row.VerifyMac);
                $("#RechIpWhiteList").val(row.RechIpWhiteList);
                $("#RechDayTotal").val(row.RechDayTotal);

                $("#UserID").val(row.UserID);
                if (row.RechStatus == 0) //禁用
                {
                    $("#radio1").removeAttr("checked");
                    $("#radio2").attr("checked", "checked");
                }
                else {
                    $("#radio2").removeAttr("checked");
                    $("#radio1").attr("checked", "checked");
                }
            } else {

                $.messager.alert('提示', '请选择数据行进行编辑!');
            }
        }
        function delReUser() {
            var row = $("#ReUserList").datagrid('getSelected');
            if (row) {
                $.messager.confirm('Confirm', '您确定要删除该数据吗?', function (r) {
                    if (r) {
                        $.post('/ReUser/DelReUser', { id: row.UserID }, function (result) {
                            if (result == "ok") {
                                $("#ReUserList").datagrid('reload');
                            }
                            else {
                                $.messager.alert('提示', result);
                            }
                        });
                    }
                });
            } else {
                $.messager.alert('提示', '请选择数据行进行操作!');
            }
        }
    </script>
}
<div id="divsearch">
    商户名称：<input type="text" name="UserName" id="UserName" style="width: 80px" />
    <a href="#" class="easyui-linkbutton" onclick="doSearch();" iconcls="icon-search">搜索</a>
</div>
<table id="ReUserList" toolbar="#divsearch">
</table>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="ReUserSave()">保存</a>
    <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
<div id="dlg" class="easyui-dialog" style="width: 800px; padding: 10px 10px" resizable="true"
    closed="true" modal="true" buttons="#dlg-buttons">
    <form id="fm" method="post" enctype="multipart/form-data">
        <table style="width: 100%">
            <tr>
                <td>项目名称：</td>
                 <td>@Html.TextBoxFor(m => m.UserTitle, new { @class = "easyui-validatebox", @style = "width:200px;", @required = "true", @name = "UserTitle" })</td>
            </tr>
            <tr>
                <td>项目经理：</td>
                <td><select id="AdminId" name="AdminId" style="width: 150px;" required="true" class="easyui-combobox"></select></td>
            </tr>
            <tr>
                <td>验证Key(mac)：</td>
                <td>@Html.TextBoxFor(m => m.VerifyMac, new { @class = "easyui-validatebox", @style = "width:250px;", @required = "true", @maxlength = "50" }) <a href="#" id="btnGenKey" style="color:red;">自动生成</a>
                接口调用充值时使用，长度不要超过50位</td>
            </tr>
            <tr>
                <td>充值时间：</td>
                <td>@Html.TextBoxFor(m => m.BeginTime, new { @class = "easyui-datetimebox", @style = "width:150px;", @required = "true", @maxlength = "50" }) - 
                @Html.TextBoxFor(m => m.EndTime, new { @class = "easyui-datetimebox", @style = "width:150px;", @required = "true", @maxlength = "50" }) 
                时间不在此范围内不能充值</td>
            </tr>
            <tr>
                <td>剩余告警值：</td>
                <td>@Html.TextBoxFor(m => m.RechAlarm, new { @class = "easyui-numberbox", @style = "width:200px;", @required = "true", @maxlength = "50" })
                剩余额小于此值后，系统最多每半小时向项目经理发送一次警告短信。</td>
            </tr>
            <tr>
                <td>每天充值限额：</td>
                <td>
                    @Html.TextBoxFor(m => m.RechDayTotal, new { @class = "easyui-numberbox", @style = "width:200px;", @required = "true", @maxlength = "50" })
                目前适用于话费充值类，每天的最大累计充值额，如果为空或为0，则不限制。
                </td>
            </tr>
            <tr>
                <td>接口调用IP白名单：</td>
                <td>@Html.TextAreaFor(m => m.RechIpWhiteList, new { @class = "easyui-textbox", @style = "width:260px;height:100px;", @multiline = "true", @required = "true", @maxlength = "200" })
                业务系统的IP地址，非白名单IP禁止调用充值接口，最多10个IP，IP间以半角逗号(,)分隔。</td>
            </tr>
            <tr>
                <td>账户状态：</td>
                <td>@Html.RadioButtonFor(m => m.RechStatus, 1, new { @id = "radio1", @name = "RechStatus" })启用
                @Html.RadioButtonFor(m => m.RechStatus, 0, new { @id = "radio2", @name = "RechStatus" })禁用
                <input type="hidden" name="UserID" id="UserID" /></td>
            </tr>
            <tr>
                <td colspan="2"><label style="color:red;font-weight:bold;">注 意：</label><br />累计充值总预算请在“充值项目管理>财务管理”中配置，达到此值后（不含确定失败），充值自动关闭。总预算是按实际面值计算，非供应商价格。总预算目前针对话费、Q币和10元、30元流量和微信红包</td>
            </tr> 
        </table> 
</form>
</div>
